package com.yksj.healthtalk.comm;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TableRow;
import android.widget.TextView;

import com.yksj.healthtalk.ui.R;

public class DateSelectListFragment extends Fragment {
	OnClickListener mClickListener;
	public void setClickListener(OnClickListener mClickListener) {
		this.mClickListener = mClickListener;
	}

	//保存日期
	List<Date> dates;
	/**
	 * @param afterDay
	 * @return
	 */
	public List<Date> getDate(int afterDay){
		List<Date> list = new ArrayList<Date>();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		//DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		list.add(calendar.getTime());
		for (int i = 0; i < afterDay; i++) {
			calendar.add(Calendar.DAY_OF_MONTH,1);
			list.add(calendar.getTime());
		}
		return list;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		dates = getDate(7);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.date_select_list_layout,null);
		TableRow tableRow1 = (TableRow)view.findViewById(R.id.tableRow1);
		TableRow tableRow2 = (TableRow)view.findViewById(R.id.tableRow2);
		for (int i = 0; i < dates.size(); i++) {
			Date date = dates.get(i);
			TextView textView = new TextView(getActivity());
			TextView textView1 = new TextView(getActivity());
			textView1.setTag(date);
			textView.setText(date.getDay()+"");
			textView.setTextSize(15);
			textView1.setTextSize(15);
			textView1.setText(date.getDate()+"");
			tableRow1.addView(textView);
			tableRow2.addView(textView1);
			textView1.setOnClickListener(mClickListener);
		}
		return view;
	}
	
	
	
}
